package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.hosp.service.ScheduleService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author:ahang
 * @create:2022-09-06 11:42
 * @Description:
 */
@Api(description = "医院显示接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private ScheduleService scheduleService;

    /**
     * 根据排班id获取预约下单数据（医院+排班数据）远程调用
     * @param scheduleId
     * @return
     */
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    //日期列表
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(@PathVariable Integer page, @PathVariable Integer limit,
                                @PathVariable String hoscode,@PathVariable String depcode) {

        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }

    //根据医院编号+科室编号+日期  查询排班列表
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(@PathVariable String hoscode,@PathVariable String depcode,@PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }

    @ApiOperation(value = "查询医院列表")
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable("page")Integer page,
                   @PathVariable("limit")Integer limit,
                   HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageModel = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return R.ok().data("pages",pageModel);
    }

    @ApiOperation(value = "根据名称模糊查询")
    @GetMapping("findByHosname/{hosname}")
    public R findByHosname(@PathVariable("hosname") String hosname){
        List<Hospital> list = hospitalService.findByHosname(hosname);
        return R.ok().data("list",list);
    }

    @ApiOperation(value = "根据医院编号获取医院详情")
    @GetMapping("{hoscode}")
    public R item(@PathVariable("hoscode") String hoscode){
        Map<String,Object> map = hospitalService.item(hoscode);
        return R.ok().data(map);
    }

}
